import { _decorator, Component, Node, Button } from 'cc';
const { ccclass, property } = _decorator;

export class UIController extends Component {
    protected view = {};
    load_all_object(root, path){
        for(let i=0; i < root.childrenCount; i++){
            this.view[path + root.children[i].name] = root.children[i];
            this.load_all_object(root.children[i], path + root.children[i].name + "/");
        }
    }

    onLoad(): void {
      this.view = {};
      this.load_all_object(this.node, "");  
    }
    public add_button_listen(view_name, caller, func){
        var view_node = this.view[view_name];
        if(!view_node){
            return;
        }
        var button = view_node.getComponent(Button);
        if(!button){
            return
        }
        view_node.on("click", func, caller);
    }
}


